--- title: Recreating Steffl's Calib keywords: fastai sidebar: home_sidebar summary: "Based on his thesis appendix" description: "Based on his thesis appendix" nb_path: "notebooks/06_calib.steffl.ipynb" ---
missing = []
there = []
for id in obsids:
try:
data = UVPDS(id, skip_download=True)
except FileNotFoundError:
print(id, "not there.")
missing.append(id)
else:
print("Got", id)
there.append(id)
cat = CatalogFilter(steffl_spica_dates[2])
cat.date = "2003-05-19"
pids = list(cat.get_euv_date().query("OBSERVATION_TYPE=='CALIB'").index)
pids
cat.set_next_day()
pids.extend(list(cat.get_euv_date().query("OBSERVATION_TYPE=='CALIB'").index))
pids
kwargs = {"x": "nx", "y": "ny", "cmap": "viridis", "clim": (0, 50)}
class FlatFielder:
def __init__(self, pid):
self.pid = pid
self.data = UVPDS(pid).xarray.astype("int16")
@property
def plot_set(self):
return self.data.hvplot(
x="spectral", y="spatial", cmap="viridis", title=self.pid
)
@property
def integrated(self):
return self.data.sum(dim="samples")
@property
def plot_integrated(self):
return self.integrated.hvplot(
x="spectral", y="spatial", cmap="viridis", title=self.pid
)
@property
def averaged(self):
return self.integrated.sel(spatial=slice(3, 61)).mean(dim="spatial")
@property
def plot_averaged(self):
return self.averaged.hvplot(x="spectral", title=self.pid)
@property
def column_std(self):
return self.integrated.sel(spatial=slice(2, 60)).std(dim="spatial")
@property
def plot_column_std(self):
return self.column_std.hvplot(x="spectral", title=f"{self.pid}, Column STD")
@property
def ff(self):
return self.integrated / self.averaged
@property
def plot_ff(self):
return self.ff.hvplot(x="spectral", y="spatial", cmap="viridis", title=self.pid)
len(pids)
pids
flatter = FlatFielder(pids[0])
flatter.plot_set
flatter.plot_integrated
flatter.plot_column_std
flatter.integrated.hvplot(x="spatial")
flatter.plot_ff
steffl = StefflCalib(pids)
pids
for m in range(4):
steffl.m = m
for i in range(15, 998):
steffl.i = i
steffl.corrections[:, i, m] = steffl.get_averaged_triplet() / steffl.get_triplet_data()[0]
steffl.plot_corrections(0)
steffl.plot_corrections(1)
steffl.corrections.shape
steffl.plot_triplet()
steffl.get_averaged_triplet()
steffl.plot()
class Col2Col:
def __init__(self, pids, i=15, m=0): # set of product_ids
self.pids = pids
self.i = i
self.m = 0
scan_df = pd.DataFrame({"pids": pids})
scan_df.index.name = "m"
stacked = []
for m, pid in scan_df.iterrows():
flatter = FlatFielder(pid.get(0))
stacked.append(flatter.integrated)
stack = np.dstack(stacked)
arr = xr.DataArray(
stack,
dims=["spectral", "spatial", "scan"],
coords={
"scan": scan_df.index.values,
"spectral": flatter.integrated.spectral,
"spatial": flatter.integrated.spatial,
},
)
arr.name = "scan_stack"
self.arr = arr
@property
def triple_columns(self):
return [self.i, self.i + 4, self.i + 8]
@property
def get_triplet(self, i=15, m=0):
cols = []
for col, scan in zip([0, 4, 8], [0, 5, 10]):
cols.append(self.arr.isel(spectral=i + col, scan=m + scan))
plots = []
for col, col_number in zip(cols, [i, i + 4, i + 8]):
plots.append(col.hvplot(label=f"Columns {col_number}, Scan {m}"))
return hv.Overlay(plots)
col2col = Col2Col(pids)
col2col.triple_columns
get_triplet()
import panel as pn
pn.extension()
pn.interact(get_triplet)
def get_all_triplets(arr, i=0):
triplets = []
for m in range(4):
plots = get_triplet(arr, i, m)
triplets.append(hv.Overlay(plots))
return triplets
triplets = get_all_triplets(arr, 15)
hv.Layout(triplets).cols(2)
col1 = arr.isel(spectral=i + 4, scan=m + 5)
col2 = arr.isel(spectral=i + 8, scan=m + 10)
(
col0.hvplot(label=f"Scan {col0.scan.data}")
* col1.hvplot(label=f"Scan {col1.scan.data}")
* col2.hvplot(label=f"Scan {col2.scan.data}")
).opts(title=f"Column {i}")
((col0 + col1 + col2) / 3).hvplot()
col_set.mean(dim=["scan", "spectral"]).hvplot()
archive_df.loc["EUV2001_093_08_35_28"]
import hvplot.xarray
import xarray as xr
ds = xr.open_dataset(fname)
ds
np.percentile(ds.window_0, (5, 95))
ds.window_0.hvplot.image(
x="spectral_dim_0", y="integrations", cmap="viridis", clim=(0, 201)
)
ds.window_0.mean("integrations").hvplot(x="spectral_dim_0")
ds.window_0.plot()
p = obsdir / "index_repaired.tab"
df = pd.read_csv(p, quotechar='"', skipinitialspace=True)
from planetarypy.pds.indexes import find_mixed_type_cols
find_mixed_type_cols(df, fix=False)
df.columns
index.columns
index[index.filename.str.startswith("EUV")].iloc[0]
obs.head()
cols = ["index start_time stop_time detector target obsid_time unknown type comment "]